package LeetCode;

/**
 * @author VX5
 * @Title: MJC
 * @ProjectName DataStructure
 * @Description: TODO
 * @date ${DAT}10:45
 */
public class interview20 {
    public boolean isNumber(String s) {
        if(s == null || s.length() == 0){
            return false;
        }
        char[] arr = s.trim().toCharArray();
        boolean isNum = false;
        boolean isPoint = false;
        boolean isE = false;
        for (int i = 0; i < arr.length; i++){
            if (arr[i] >= '0' && arr[i] <= '9'){
                isNum = true;
            }else if (arr[i] == '.'){
                if (isPoint||isE){
                    return false;
                }
                isPoint = true;
            }else if (arr[i] == 'e' || arr[i] == 'E'){
                if (isE || !isNum){
                    return false;
                }
                isE = true;
                isNum = false;
            }else if (arr[i] == '+' || arr[i] == '-'){
                if (i != 0 && arr[i - 1] !='e' && arr[i-1] != 'E') {
                    return false;
                }
            }else {
                return false;
            }
        }
        return isNum;
    }
}
